package com.timothy.junk.common.parse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
import android.content.res.XmlResourceParser;
import com.timothy.junk.R;
import com.timothy.junk.tfund.bean.TFund;

public class TFundParse {

	public static List<TFund> getTFundList(Context context) {
		List<TFund> tFundList = new ArrayList<TFund>();
		XmlResourceParser xrp = context.getResources().getXml(R.xml.tfunds);
		try {
			TFund tFund = null;
			while (xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
				if (xrp.getEventType() == XmlResourceParser.START_TAG) {
					String tagName = xrp.getName();
					if (tagName.equals("tfund")) {
						tFund = new TFund();
					}
					if (tagName.equals("seq") && tFund != null) {
						tFund.setSeq(xrp.nextText());
					}
					if (tagName.equals("tfund_code") && tFund != null) {
						tFund.setTfundCode(xrp.nextText());
					}
					if (tagName.equals("tfund_name") && tFund != null) {
						tFund.setTfundName(xrp.nextText());
					}
					if (tagName.equals("end_date") && tFund != null) {
						tFund.setEndDate(xrp.nextText());
					}
				}

				if (xrp.getEventType() == XmlResourceParser.END_TAG) {
					String tagName = xrp.getName();
					if (tagName.equals("tfund")) {
						tFundList.add(tFund);
					}
				}
				xrp.next();
			}
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return tFundList;
	}

}
